package com.dotflat.fin.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ：Ron
 * @date ：Created in 2020/3/17 22:11
 */

@Configuration
public class WxConfig {
    @Autowired
    private WxMaProperties maProperties;

    @Autowired
    private WxMpProperties mpProperties;

    @Bean(name = "wxMpPayConfig")
    public WxPayConfig wxMpPayConfig() {
        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(mpProperties.getAppId());
        payConfig.setMchId(mpProperties.getMchId());
        payConfig.setMchKey(mpProperties.getMchKey());
        payConfig.setNotifyUrl(mpProperties.getNotifyUrl());
        payConfig.setKeyPath(mpProperties.getKeyPath());
        payConfig.setTradeType("JSAPI");
        payConfig.setSignType("MD5");
        return payConfig;
    }

    @Bean(name = "wxMaPayConfig")
    public WxPayConfig wxMaPayConfig() {
        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(maProperties.getAppId());
        payConfig.setMchId(maProperties.getMchId());
        payConfig.setMchKey(maProperties.getMchKey());
        payConfig.setNotifyUrl(maProperties.getNotifyUrl());
        payConfig.setKeyPath(maProperties.getKeyPath());
        payConfig.setTradeType("JSAPI");
        payConfig.setSignType("MD5");
        return payConfig;
    }

    @Bean(name = "wxMpPayService")
    public WxPayService wxMpPayService(WxPayConfig wxMpPayConfig) {
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(wxMpPayConfig);
        return wxPayService;
    }

    @Bean(name = "wxMaPayService")
    public WxPayService wxMaPayService(WxPayConfig wxMaPayConfig) {
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(wxMaPayConfig);
        return wxPayService;
    }
}
